//------------Sonic CD BossFoot Script-------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

//-------Aliases-------//
#alias 50: TYPE_BOSSFOOT
#alias Player.Value4:Player.Invincible


function BossFoot_Function64
	ArrayPos0=Object.Value0
	Object.XPos=Object[ArrayPos0].XPos
	Object.XPos-=720896
	Object.XPos+=Object.Value6
	Object.YPos=Object[ArrayPos0].YPos
	Object.YPos+=917504
	Object.YPos+=Object.Value7
endfunction


function BossFoot_Function65
	SetBit(Object.Value4,4,1)
	ArrayPos0=Object.Value0
	SetBit(Object[ArrayPos0].Value4,4,1)
	ArrayPos1=Object[ArrayPos0].Value0
	SetBit(Object[ArrayPos1].Value4,4,1)
	Screen.ShakeY=4
	ArrayPos0=Object.Value1
	ArrayPos0++
	if Object[ArrayPos0].Value5>2
		ArrayPos0--
		Object[ArrayPos0].YPos-=98304
		ArrayPos0--
		Object[ArrayPos0].YPos-=98304
	endif
	PlaySfx(SfxName[MechStep], 0)
#platform: Use_Haptics
	HapticEffect(100,0,0,0)
#endplatform
endfunction


function BossFoot_Function66
	GetBit(temp0,Object.Value4,4)
	if temp0==0
		CallFunction(BossFoot_Function64)
	else
		GetBit(temp0,Object.Value4,5)
		if temp0==1
			temp6=Object.Value2
			temp7=Object.Value5
			if Object.State!=3
				FlipSign(temp6)
				FlipSign(temp7)
			endif
			ArrayPos0=Object.Value0
			Object[ArrayPos0].XPos-=temp6
			Object[ArrayPos0].YPos+=temp7
			ArrayPos1=Object[ArrayPos0].Value0
			Object[ArrayPos1].XPos-=temp6
			Object[ArrayPos1].YPos+=temp7
			ArrayPos0=Object[ArrayPos1].Value0
			Object[ArrayPos0].XPos-=temp6
			Object[ArrayPos0].YPos+=temp7
			ArrayPos1=Object[ArrayPos0].Value0
			Object[ArrayPos1].XPos-=temp6
			Object[ArrayPos1].YPos+=temp7
		endif
	endif
endfunction


function BossFoot_Function67
	temp0=Object.YPos
	ObjectTileCollision(0,0,20,0)
	if CheckResult==1
		GetBit(temp0,Object.Value4,5)
		if temp0==1
			temp0-=Object.YPos
			ArrayPos0=Object.Value0
			Object[ArrayPos0].YPos-=temp0
			ArrayPos1=Object[ArrayPos0].Value0
			Object[ArrayPos1].YPos-=temp0
			ArrayPos0=Object[ArrayPos1].Value0
			Object[ArrayPos1].YPos-=temp0
			ArrayPos1=Object[ArrayPos0].Value0
			Object[ArrayPos1].YPos-=temp0
		endif
	endif
endfunction


event ObjectMain
	switch Object.State
	case 0
		Object.Value2=16384
		Object.Value5=32768
		Object.Value6=-524288
		Object.Value7=1048576
		SetBit(Object.Value4,0,1)
		CallFunction(BossFoot_Function64)
		Object.State=2
		break
	case 1
		Object.Value6-=Object.Value2
		Object.Value7+=Object.Value5
		temp1=1
		GetBit(temp0,Object.Value4,4)
		CheckResult=temp0
		GetBit(temp0,Object.Value4,7)
		CheckResult&=temp0
		if CheckResult==1
			if Object.Value7>=786432
				SetBit(Object.Value4,0,1)
				Object.State=2
				temp1=0
			endif
		else
			if Object.Value7>=1048576
				SetBit(Object.Value4,0,1)
				Object.State=2
				temp1=0
			endif
		endif
		if temp1==1
			CallFunction(BossFoot_Function66)
			ObjectTileCollision(0,0,20,0)
			if CheckResult==1
				CallFunction(BossFoot_Function65)
			endif
		endif
		break
	case 2
		GetBit(temp0,Object.Value4,4)
		if temp0==0
			CallFunction(BossFoot_Function64)
			ObjectTileCollision(0,0,20,0)
			if CheckResult==1
				CallFunction(BossFoot_Function65)
			endif
		endif
		break
	case 3
		Object.Value6+=Object.Value2
		Object.Value7-=Object.Value5
		if Object.Value7<=0
			Object.Value6=0
			Object.Value7=0
			SetBit(Object.Value4,0,1)
			Object.State=4
		endif
		CallFunction(BossFoot_Function66)
		break
	case 4
		CallFunction(BossFoot_Function64)
		break
	case 5
		ArrayPos0=Object.Value1
		ArrayPos1=Object[ArrayPos0].Value1
		ArrayPos0=Object[ArrayPos1].Value1
		ArrayPos1=Object[ArrayPos0].Value1
		Object.XPos=Object[ArrayPos1].XPos
		Object.XPos-=655360
		Object.YPos=Object[ArrayPos1].YPos
		break
	case 6
		GetBit(temp0,Object.Value4,4)
		if temp0==0
			Object.Value2-=1632
		else
			Object.Value2+=1632
		endif
		Object.Value5+=5728
		Object.XPos+=Object.Value2
		Object.YPos+=Object.Value5
		if Object.OutOfBounds==1
			Object.Type=TypeName[BlankObject]
			Object.Priority=0
		endif
		break

	endswitch


foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
	if Object.State<6
		if object[currentPlayer].value7==0
			BoxCollisionTest(C_TOUCH, object.entityPos,-28,-20,26,20, currentPlayer, object[currentPlayer].value40, object[currentPlayer].value38, object[currentPlayer].value41, object[currentPlayer].value39)
			if CheckResult==1
				ArrayPos0=Object.Value0
				ArrayPos1=Object[ArrayPos0].Value0
				ArrayPos0=Object[ArrayPos1].Value0
				ArrayPos1=Object[ArrayPos0].Value0
				Object[ArrayPos1].Animation=1
				Object[ArrayPos1].Direction=180
				object[currentPlayer].State=PlayerObject_Hurt
				if object[currentPlayer].XPos>Object.XPos
					object[currentPlayer].Speed=131072
				else
					object[currentPlayer].Speed=-131072
				endif
			endif
		endif
	endif
next
endevent


event ObjectDraw
	DrawSprite(0)
endevent


event ObjectStartup
	LoadSpriteSheet("RRZ/Objects.gif")
	SpriteFrame(-32,-20,58,40,206,35)
endevent

event RSDK
	LoadSpriteSheet("Global/Display.gif")
	SetEditorIcon(Icon0,SingleIcon,-16,-16,32,32,206,35)
endevent
